package com.itshare.video.mapper;

import com.itshare.video.pojo.po.VideoComment;
import com.itshare.video.pojo.po.VideoCommentExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface VideoCommentMapper {
    long countByExample(VideoCommentExample example);

    int deleteByExample(VideoCommentExample example);

    @Delete({
        "delete from t_video_comment",
        "where comment_id = #{commentId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long commentId);

    @Insert({
        "insert into t_video_comment (REVISION, CREATED_BY, ",
        "CREATED_TIME, UPDATED_BY, ",
        "UPDATED_TIME, content, ",
        "from_user_id, course_id, ",
        "video_id, is_reply, ",
        "parent_comment_id, delete_status, ",
        "from_user_name, at_user_name, ",
        "at_user_id, from_avatar)",
        "values (#{revision,jdbcType=INTEGER}, #{createdBy,jdbcType=VARCHAR}, ",
        "#{createdTime,jdbcType=TIMESTAMP}, #{updatedBy,jdbcType=VARCHAR}, ",
        "#{updatedTime,jdbcType=TIMESTAMP}, #{content,jdbcType=VARCHAR}, ",
        "#{fromUserId,jdbcType=INTEGER}, #{courseId,jdbcType=INTEGER}, ",
        "#{videoId,jdbcType=BIGINT}, #{isReply,jdbcType=INTEGER}, ",
        "#{parentCommentId,jdbcType=INTEGER}, #{deleteStatus,jdbcType=INTEGER}, ",
        "#{fromUserName,jdbcType=VARCHAR}, #{atUserName,jdbcType=VARCHAR}, ",
        "#{atUserId,jdbcType=INTEGER}, #{fromAvatar,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="commentId", before=false, resultType=Long.class)
    int insert(VideoComment record);

    int insertSelective(VideoComment record);

    List<VideoComment> selectByExampleWithRowbounds(VideoCommentExample example, RowBounds rowBounds);

    List<VideoComment> selectByExample(VideoCommentExample example);

    @Select({
        "select",
        "comment_id, REVISION, CREATED_BY, CREATED_TIME, UPDATED_BY, UPDATED_TIME, content, ",
        "from_user_id, course_id, video_id, is_reply, parent_comment_id, delete_status, ",
        "from_user_name, at_user_name, at_user_id, from_avatar",
        "from t_video_comment",
        "where comment_id = #{commentId,jdbcType=BIGINT}"
    })
    @ResultMap("com.itshare.video.mapper.VideoCommentMapper.BaseResultMap")
    VideoComment selectByPrimaryKey(Long commentId);

    int updateByExampleSelective(@Param("record") VideoComment record, @Param("example") VideoCommentExample example);

    int updateByExample(@Param("record") VideoComment record, @Param("example") VideoCommentExample example);

    int updateByPrimaryKeySelective(VideoComment record);

    @Update({
        "update t_video_comment",
        "set REVISION = #{revision,jdbcType=INTEGER},",
          "CREATED_BY = #{createdBy,jdbcType=VARCHAR},",
          "CREATED_TIME = #{createdTime,jdbcType=TIMESTAMP},",
          "UPDATED_BY = #{updatedBy,jdbcType=VARCHAR},",
          "UPDATED_TIME = #{updatedTime,jdbcType=TIMESTAMP},",
          "content = #{content,jdbcType=VARCHAR},",
          "from_user_id = #{fromUserId,jdbcType=INTEGER},",
          "course_id = #{courseId,jdbcType=INTEGER},",
          "video_id = #{videoId,jdbcType=BIGINT},",
          "is_reply = #{isReply,jdbcType=INTEGER},",
          "parent_comment_id = #{parentCommentId,jdbcType=INTEGER},",
          "delete_status = #{deleteStatus,jdbcType=INTEGER},",
          "from_user_name = #{fromUserName,jdbcType=VARCHAR},",
          "at_user_name = #{atUserName,jdbcType=VARCHAR},",
          "at_user_id = #{atUserId,jdbcType=INTEGER},",
          "from_avatar = #{fromAvatar,jdbcType=VARCHAR}",
        "where comment_id = #{commentId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(VideoComment record);
}